package com.yi.wood.service.impl;

import com.yi.wood.dao.ClassificationDao;
import com.yi.wood.entity.Classification;
import com.yi.wood.service.ClassificationService;
import com.yi.wood.service.constant.ClassificationStatusEnum;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @author MoYi
 * create date 2019/4/5 17:28
 */
public abstract class AbstractClassificationServiceImpl implements ClassificationService {

    @Resource
    private ClassificationDao classificationDao;

    @Override
    public Classification findClassById(Long id) {
        Optional<Classification> optional = classificationDao.findById(id);
        return optional.orElse(null);
    }

    @Override
    public Classification addData(Classification classification) {
        classification.setCreateTime(new Date());
        classification.setStatus(ClassificationStatusEnum.VALID.getStatus());
        classificationDao.save(classification);
        return null;
    }

    @Override
    public void delData(Long id) {
        classificationDao.deleteById(id);
    }

    @Override
    public Classification updateData(Classification classification) {
        return classificationDao.save(classification);
    }

    @Override
    public List<Classification> queryAllClass() {
        return classificationDao.findAll();
    }

    @Override
    public List<Classification> queryClassByLevel(Integer level, Integer type) {
        return classificationDao.findByLevelEqualsAndTypeEquals(level, type);
    }

    @Override
    public List<Classification> queryClassByParentId(Long parentId) {
        return classificationDao.findByParentIdEquals(parentId);
    }

    @Override
    public List<Classification> queryClassByRoleId(Long roleId) {
        return classificationDao.findByParentIdEquals(roleId);
    }

    @Override
    public Page<Classification> pageDataList(Example<Classification> example, Pageable pageable) {
        return null;
    }
}
